package com.itwill.ecom.ordersDetail;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.itwill.ecom.product.ProductBeans;

@Repository("ordersDetailDao")
public class OrdersDetailDaoImpl implements OrdersDetailDao {
	public final static String namespace="com.itwill.ecom.ordersDetail.OrdersDetailMapper";
	@Autowired
	private SqlSession session;
	
	public OrdersDetailDaoImpl() {
		System.out.println("##### OrdersDetailDao() 기본");
	}

	public void setSession(SqlSession session) {
		System.out.println("##### setSession(SqlSession session)");
		this.session = session;
	}

	public SqlSession getSession() {
		System.out.println("##### getSession()");
		return session;
	}
	
	//상세보기 추가
	@Override
	public int create(OrdersDetailBeans detailBeans){
		return session.insert(namespace+".create", detailBeans);
	}
	
	//전체 상세보기 검색
	@Override
	public List<OrdersDetailBeans> getAll(){
		return session.selectList(namespace+".selectAll");
	}
	
	//상세보기 검색
	@Override
	public OrdersDetailBeans getNo(int no){
		return session.selectOne(namespace+".select", no);
	}

	//주문에 대한 상세보기 리스트 검색
	@Override
	public List<OrdersDetailBeans> getDetail(int ordersno){
		return session.selectList(namespace+".selectorders", ordersno);
	}
	
	//상세보기 삭제
	@Override
	public int delete(int detail_no){
		return session.delete(namespace+".delete", detail_no);
	}
	
	// 주문번호로 삭제
	@Override
	public int deleteDetails(int o_no) throws Exception {
		return session.delete(namespace + ".deleteByOno", o_no);
	}
}
